package com.fengxu.gamescript.provide

import com.fengxu.gamescript.data.Conf
import com.fengxu.gamescript.util.CommonUtils
import com.fengxu.http.proxy.FxHttpMain

/**
 * api代码工厂，提供创建好的api接口的动态代理类
 */
object ProviderFactory {

    // 请求基地址
    var BaseUrl = "${CommonUtils.getHost()}:8005"
        private set

    // 消息页h5的网络地址
    var MsgWebBaseUrl = "${CommonUtils.getHost()}:8010"
        private set

    val dataProvider:DataProvider by lazy {
        FxHttpMain.Builder()
            .startLog(false)
            .baseUrl(BaseUrl)
            .addInterceptor({
                it.addHeader(getBaseHeader())
            },"/")
            .build(DataProvider::class.java)
    }


    /**
     * 获取请求头
     */
    private fun getBaseHeader():MutableMap<String, String>{
        Conf.getConf().run {
            return mutableMapOf(
                "uid" to (email ?: ""),
                "s" to if(pwd == null){""}else{ CommonUtils.pEnc(pwd) }
            )
        }
    }

}